package com.market.manager.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.market.dao.MessageDao;
import com.market.domain.Location;
import com.market.domain.Message;
import com.market.domain.Picture;
import com.market.domain.User;
import com.market.manager.MessageManager;
@Service("messageManager")
public class MessageManagerImpl extends
		GenericManagerImpl<MessageDao, Message, Long> implements
		MessageManager {
	
	@Autowired
	@Override
	public void setDao(MessageDao dao) {
	 super.dao = dao;
	}
	
	public Message fetchOne(Long id){
		Message message = this.dao.findById(id);
		message.setUsers(this.fetchUsers(message));
		message.setLocations(this.fetchLocations(message));
		message.setPictures(this.fetchPictures(message));
		return message;
	}

	public Message fetchOne(Message message) {
		if(message != null && message.getIsNew()==false){
			return this.fetchOne(message.getId());
		}
		return message;
	}

	public List<User> fetchUsers(Message message) {
		return this.dao.findUsers(message);
	}
	
	public List<Location> fetchLocations(Message message) {
		return this.dao.findLocations(message);
	}

	public List<Picture> fetchPictures(Message message) {
		return this.dao.findPictures(message);
	}

	public List<Message> fetchAllBlogs() {
		return this.dao.findAllBlogs();
	}

	

	

}
